home *** CD-ROM | disk | FTP | other *** search
- /*
- File: PIUtilities.c
-
- Copyright 1993 by Adobe Systems, Inc.
-
- C source file for plug-in callback utilities.
- */
-
- #include <Types.h>
-
- #include "PIUtilities.h"
-
- #include "PITypes.h"
- #include "PIGeneral.h"
-
- /*****************************************************************************/
-
- Boolean HostBufferProcsAvailable (BufferProcs *procs, Boolean *tooNew)
- {
-
- Boolean available = TRUE;
- Boolean myTooNew = FALSE;
-
- if (!procs)
- available = FALSE;
-
- else if (procs->bufferProcsVersion < kCurrentBufferProcsVersion)
- available = FALSE;
-
- else if (procs->bufferProcsVersion > kCurrentBufferProcsVersion)
- {
-
- available = FALSE;
-
- myTooNew = TRUE;
-
- }
-
- else if (procs->numBufferProcs < kCurrentBufferProcsCount ||
- !procs->allocateProc ||
- !procs->lockProc ||
- !procs->unlockProc ||
- !procs->freeProc ||
- !procs->spaceProc)
- available = FALSE;
-
- if (tooNew)
- *tooNew = myTooNew;
-
- return available;
-
- }
-
- /*****************************************************************************/
-
- Boolean WarnHostBufferProcsAvailable (BufferProcs *procs)
- {
-
- #define tooOldID 16997
- #define tooNewID 16998
-
- Boolean available, tooNew;
-
- available = HostBufferProcsAvailable (procs, &tooNew);
-
- if (!available)
- ShowAlert (tooNew ? tooNewID : tooOldID);
-
- return available;
-
- #undef tooOldID
- #undef tooNewID
-
- }
-
- /*****************************************************************************/
-
- int32 HostBufferSpace (BufferProcs *procs)
- {
-
- if (!HostBufferProcsAvailable (procs, NULL))
- return 0;
-
- else
- return (*procs->spaceProc) ();
-
- }
-
- /*****************************************************************************/
-
- OSErr HostAllocateBuffer (BufferProcs *procs, int32 size, BufferID *bufferID)
- {
-
- *bufferID = 0;
-
- if (!HostBufferProcsAvailable (procs, NULL))
- return memFullErr;
-
- else
- return (*procs->allocateProc) (size, bufferID);
-
- }
-
- /*****************************************************************************/
-
- void HostFreeBuffer (BufferProcs *procs, BufferID bufferID)
- {
-
- if (HostBufferProcsAvailable (procs, NULL))
- (*procs->freeProc) (bufferID);
-
- }
-
- /*****************************************************************************/
-
- Ptr HostLockBuffer (BufferProcs *procs, BufferID bufferID, Boolean moveHigh)
- {
-
- if (HostBufferProcsAvailable (procs, NULL))
- return (*procs->lockProc) (bufferID, moveHigh);
- else
- return NULL;
-
- }
-
- /*****************************************************************************/
-
- void HostUnlockBuffer (BufferProcs *procs, BufferID bufferID)
- {
-
- if (HostBufferProcsAvailable (procs, NULL))
- (*procs->unlockProc) (bufferID);
-
- }
-
- /*****************************************************************************/
-
- OSErr HostAllocateStripBuffer (BufferProcs *procs,
- int32 rowBytes,
- int16 minHeight,
- int16 maxHeight,
- int16 numBuffers,
- int16 *actualHeight,
- BufferID *bufferID)
- {
-
- int16 curHeight;
- int32 curSize;
- OSErr curResult = noErr;
- int32 availableSpace = HostBufferSpace (procs) / numBuffers;
-
- int32 availableHeight = availableSpace / rowBytes;
-
- curHeight = (availableHeight < maxHeight) ? (int16) availableHeight
- : maxHeight;
-
- ++curHeight;
-
- curSize = rowBytes * (int32) curHeight;
-
- *bufferID = 0;
-
- while (!*bufferID && curHeight > minHeight)
- {
-
- --curHeight;
- curSize -= rowBytes;
-
- curResult = HostAllocateBuffer (procs, curSize, bufferID);
-
- }
-
- if (*bufferID)
- *actualHeight = curHeight;
-
- return curResult;
-
- }
-
- /*****************************************************************************/
-
- Boolean HostResourceProcsAvailable (ResourceProcs *procs, Boolean *tooNew)
- {
-
- Boolean available = TRUE;
- Boolean myTooNew = FALSE;
-
- if (!procs)
- available = FALSE;
-
- else if (procs->resourceProcsVersion < kCurrentResourceProcsVersion)
- available = FALSE;
-
- else if (procs->resourceProcsVersion > kCurrentResourceProcsVersion)
- {
-
- available = FALSE;
-
- myTooNew = TRUE;
-
- }
-
- else if (procs->numResourceProcs < kCurrentResourceProcsCount ||
- !procs->countProc ||
- !procs->getProc ||
- !procs->deleteProc ||
- !procs->addProc)
- available = FALSE;
-
- if (tooNew)
- *tooNew = myTooNew;
-
- return available;
-
- }
-
- /*****************************************************************************/
-
- Boolean WarnHostResourceProcsAvailable (ResourceProcs *procs)
- {
-
- #define tooOldID 16999
- #define tooNewID 16998
-
- Boolean available, tooNew;
-
- available = HostResourceProcsAvailable (procs, &tooNew);
-
- if (!available)
- ShowAlert (tooNew ? tooNewID : tooOldID);
-
- return available;
-
- #undef tooOldID
- #undef tooNewID
-
- }
-
- /*****************************************************************************/
-
- int16 HostCountPIResources (ResourceProcs *procs, ResType type)
- {
-
- if (!HostResourceProcsAvailable (procs, NULL))
- return 0;
-
- else
- return (*procs->countProc) (type);
-
- }
-
- /*****************************************************************************/
-
- Handle HostGetPIResource (ResourceProcs *procs, ResType type, int16 index)
- {
-
- if (!HostResourceProcsAvailable (procs, NULL))
- return NULL;
-
- else
- return (*procs->getProc) (type, index);
-
- }
-
- /*****************************************************************************/
-
- void HostDeletePIResource (ResourceProcs *procs, ResType type, int16 index)
- {
-
- if (HostResourceProcsAvailable (procs, NULL))
- (*procs->deleteProc) (type, index);
-
- }
-
- /*****************************************************************************/
-
- OSErr HostAddPIResource (ResourceProcs *procs, ResType type, Handle data)
- {
-
- if (!HostResourceProcsAvailable (procs, NULL))
- return memFullErr;
-
- else
- return (*procs->addProc) (type, data);
-
- }
-
- /*****************************************************************************/
-
- Boolean HostHandleProcsAvailable (HandleProcs *procs, Boolean *tooNew)
- {
-
- /* We only require the new, dispose, set size, and get size procs. */
- /* Lock and unlock can usually be gotten around without resorting */
- /* to callbacks. */
-
- #define kCoreHandleProcsCount 4
-
- Boolean available = TRUE;
- Boolean myTooNew = FALSE;
-
- if (!procs)
- available = FALSE;
-
- else if (procs->handleProcsVersion < kCurrentHandleProcsVersion)
- available = FALSE;
-
- else if (procs->handleProcsVersion > kCurrentHandleProcsVersion)
- {
-
- available = FALSE;
-
- myTooNew = TRUE;
-
- }
-
- else if (procs->numHandleProcs < kCoreHandleProcsCount ||
- !procs->newProc ||
- !procs->disposeProc ||
- !procs->getSizeProc ||
- !procs->setSizeProc)
- available = FALSE;
-
- if (tooNew)
- *tooNew = myTooNew;
-
- return available;
-
- }
-
- /*****************************************************************************/
-
- Boolean WarnHostHandleProcsAvailable (HandleProcs *procs)
- {
-
- #define tooOldID 16999
- #define tooNewID 16998
-
- Boolean available, tooNew;
-
- available = HostHandleProcsAvailable (procs, &tooNew);
-
- if (!available)
- ShowAlert (tooNew ? tooNewID : tooOldID);
-
- return available;
-
- #undef tooOldID
- #undef tooNewID
-
- }
-
- /*****************************************************************************/
-
- Handle HostNewHandle (HandleProcs *procs, int32 size)
- {
-
- if (!HostHandleProcsAvailable (procs, NULL))
- return NewHandle (size);
-
- else
- return (*procs->newProc) (size);
-
- }
-
- /*****************************************************************************/
-
- void HostDisposeHandle (HandleProcs *procs, Handle h)
- {
-
- if (!HostHandleProcsAvailable (procs, NULL))
- DisposHandle (h);
-
- else
- (*procs->disposeProc) (h);
-
- }
-
- /*****************************************************************************/
-
- int32 HostGetHandleSize (HandleProcs *procs, Handle h)
- {
-
- if (!HostHandleProcsAvailable (procs, NULL))
- return GetHandleSize (h);
-
- else
- return (*procs->getSizeProc) (h);
-
- }
-
- /*****************************************************************************/
-
- OSErr HostSetHandleSize (HandleProcs *procs, Handle h, int32 newSize)
- {
-
- if (!HostHandleProcsAvailable (procs, NULL))
- {
-
- SetHandleSize (h, newSize);
-
- return MemError ();
-
- }
-
- else
- return (*procs->setSizeProc) (h, newSize);
-
- }
-
- /*****************************************************************************/
-
- Ptr HostLockHandle (HandleProcs *procs, Handle h, Boolean moveHigh)
- {
-
- if (procs &&
- procs->handleProcsVersion == kCurrentHandleProcsVersion &&
- procs->numHandleProcs >= 6 &&
- procs->lockProc &&
- procs->unlockProc)
- {
-
- return (*procs->lockProc) (h, moveHigh);
-
- }
-
- else
- {
-
- if (moveHigh)
- MoveHHi (h);
-
- HLock (h);
-
- return *h;
-
- }
-
- }
-
- /*****************************************************************************/
-
- void HostUnlockHandle (HandleProcs *procs, Handle h)
- {
-
- if (procs &&
- procs->handleProcsVersion == kCurrentHandleProcsVersion &&
- procs->numHandleProcs >= 6 &&
- procs->lockProc &&
- procs->unlockProc)
- {
-
- (*procs->unlockProc) (h);
-
- }
-
- else
- {
-
- HUnlock (h);
-
- }
-
- }
-
- /*****************************************************************************/
-
-